//
// Created by gogoqiu on 2022/2/11.
//

#ifndef RAPIDSVN_CMAKE_PREFERENCEITEM_H
#define RAPIDSVN_CMAKE_PREFERENCEITEM_H

#include "wx/wx.h"

/**
 * 核心数据
 * key
 * title
 * value
 */
class PreferenceItem{
    friend class PreferenceView;
protected:
    wxString key;
    wxString value;
    wxString defaultValue;

    bool valueIsNull;

    PreferenceItem(){
        valueIsNull = false;
    };
public:
    static PreferenceItem* NullValueItem( const wxString& key,
                                          const wxString& defaultValue){
        auto* item = new PreferenceItem;
        item->key = key;
        //item->value = 0;
        return item;
    }

    PreferenceItem( const wxString& key,
                    const wxString& value,
                    const wxString& defaultValue){
        this->key = key;
        this->value = value;
        this->defaultValue = defaultValue;
        valueIsNull = false;
    }

    PreferenceItem( const wxString& key,
                    const wxString& value,
                    const wxString& defaultValue,
                    bool _valueIsNull ){
        this->key = key;
        this->value = value;
        this->defaultValue = defaultValue;
        valueIsNull = _valueIsNull;
    }

    //
    wxString getSql( wxString tag ){
        wxString sql;
        wxString _value = value;
        //把26个字母打一遍，然后通过php的addslashes查看哪些字符变化了
        _value.Replace("\\", "\\\\");
        _value.Replace("\"", "\\\"");
        _value.Replace("\'", "\\\'");
        //sql.sprintf(base, filename, filesize, file_hash);
        sql.sprintf("insert into preferences( tag, key, defaultValue, value ) values( '%s', '%s', '%s', '%s' )",
                    tag, key, this->defaultValue, _value );
        //wxString _sql = sql.mb_str(wxConvUTF8);
        return sql;
    }

    wxString getKey(){
        return key;
    }

    wxString getValue(){
        return value;
    }

    wxString getDefaultValue(){
        return defaultValue;
    }

    void setValueIsNull( bool _valueIsNull ){
        this->valueIsNull = _valueIsNull;
    }

    void setValue( wxString v ){
        value = v;
    }

    bool getValueIsNull(  ) const{
        return this->valueIsNull;
    }
};


#endif //RAPIDSVN_CMAKE_PREFERENCEITEM_H
